package com.example.util;

/**
 * @author leal123
 * @title ParseJsonData
 * @date 8/16/2022 9:39 PM
 * @description
 */

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class ParseJsonUtil {

    public static JSONObject getJsonData(String data) {
        try {
            return JSONObject.parseObject(data);
        } catch (Exception e) {
            return null;
        }
    }

    public static String getJsonData(Object obj) {
        try {
            return JSONObject.toJSONString(obj);
        } catch (Exception e) {
            return null;
        }
    }

    public static JSONObject getJson(Object obj) {
        try {
            String jsonString = getJsonData(obj);
            return getJsonData(jsonString);
        } catch (Exception e) {
            return null;
        }
    }

    public static JSONArray getJsonArray(String text) {
        try {
            return JSONArray.parseArray(text);
        } catch (Exception e) {
            return null;
        }
    }
}

